package pony.struts.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import pony.model.Hello;
import pony.struts.formbeans.HelloActionForm;

public class HelloAction extends Action {
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, 
				HttpServletRequest request, HttpServletResponse response) {
		HelloActionForm helloForm = (HelloActionForm)form;
		
		Hello hello = new Hello();
		String userName = hello.sayHello(helloForm.getName());
		String userTelNum = hello.showTelNum(helloForm.getTelNum());
		
		request.setAttribute("hello", hello);
		request.setAttribute("userName", userName);
		request.setAttribute("userTelNum", userTelNum);
		
		double bmi = hello.doBMI(helloForm.getHeight(), helloForm.getWeight());
		request.setAttribute("bmi", bmi);
		
		if(bmi < 18.5) {
			return mapping.findForward("tooThin");
		} else if(bmi > 24) {
			return mapping.findForward("tooFat");
		}
		
		return mapping.findForward("sayHello");
	}
}
